package com.imau.config;

import org.apache.ibatis.session.Configuration;
import org.mybatis.spring.SqlSessionFactoryBean;
import org.mybatis.spring.mapper.MapperScannerConfigurer;
import org.springframework.context.annotation.Bean;

import javax.sql.DataSource;

public class MybatisConfig {

    @Bean
    public SqlSessionFactoryBean sessionFactory (DataSource dataSource)
    {
        SqlSessionFactoryBean sessionFactoryBean  = new SqlSessionFactoryBean();

        sessionFactoryBean.setTypeAliasesPackage("com.imau.bean");

        sessionFactoryBean.setDataSource(dataSource);
        Configuration configuration =new Configuration();
        configuration.setMapUnderscoreToCamelCase(true);

        sessionFactoryBean.setConfiguration(configuration);
        return sessionFactoryBean;
    }

    @Bean
    public MapperScannerConfigurer mapperScannerConfigurer()
    {
        MapperScannerConfigurer msc = new MapperScannerConfigurer();
        msc.setBasePackage("com.imau.dao");

        return msc;
    }
}
